@echo off
chcp 65001 > nul
echo 🚀 启动少儿英语平台集群...

echo 📦 请确保 Redis 已启动...
echo 🔨 编译项目...
call cd /d "%~dp0.."
mvn clean package -DskipTests

if %errorlevel% neq 0 (
    echo ❌ 项目编译失败
    pause
    exit /b 1
)
echo ✅ 项目编译成功

echo 🐱 启动 Tomcat 集群节点...

echo 启动节点1 (端口 8080)...
set INSTANCE_ID=node1
start "Node1" java -jar target\child-english-platform-1.0.0.jar --server.port=8080

timeout /t 5

echo 启动节点2 (端口 8081)...
set INSTANCE_ID=node2  
start "Node2" java -jar target\child-english-platform-1.0.0.jar --server.port=8081

timeout /t 5

echo 启动节点3 (端口 8082)...
set INSTANCE_ID=node3
start "Node3" java -jar target\child-english-platform-1.0.0.jar --server.port=8082

echo ⏳ 等待应用启动...
timeout /t 10

echo 🔀 请手动启动 Nginx...
echo nginx -c %~dp0..\nginx\nginx-cluster.conf

echo.
echo ==========================================
echo ✅ 集群启动完成!
echo 🌐 访问地址: http://localhost
echo 📊 集群监控: http://localhost/cluster/health
echo 🔍 节点健康检查:
echo    - 节点1: http://localhost:8080/cluster/health
echo    - 节点2: http://localhost:8081/cluster/health
echo    - 节点3: http://localhost:8082/cluster/health
echo ==========================================
pause